package com.lemon.components.ant.project;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.lemon.components.ant.beans.ProjectInfo;
import com.lemon.components.ant.project.beans.ColumnInfo;
import com.lemon.components.ant.project.beans.EnumInfo;
import com.lemon.components.ant.project.beans.TableInfo;
import com.lemon.components.ant.util.ConfigUtil;
import com.lemon.components.ant.util.FileUtil;
import com.lemon.components.ant.util.PathUtil;
import com.lemon.components.ant.util.TemplateUtil;
import com.lemon.components.common.result.ResultBase;
import com.lemon.ui.codemaker.component.RecentlyFile;
import com.system.core.security.NameUtil;

public class ProjectMaker {
	
	public static PathUtil pathUtil;
	
	public static void makeAssemble(ProjectInfo projectInfo) {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/dockerfile", pathUtil.getModelPath("assemble").getPath() +"dockerfile", projectInfo);
	}
	
	public static void makeConfig(ProjectInfo projectInfo) throws Exception {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/ShiroTagsFreeMarkerCfg.java", pathUtil.getConfigPackagePath().getPath()+"shiro/ShiroTagsFreeMarkerCfg.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/net/CookieConfig.java", pathUtil.getConfigPackagePath().getPath()+"net/CookieConfig.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/net/RedisConfig.java", pathUtil.getConfigPackagePath().getPath()+"net/RedisConfig.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/net/WebConfig.java", pathUtil.getConfigPackagePath().getPath()+"net/WebConfig.java", projectInfo);
		
		FileUtils.copyDirectory(new File(projectInfo.getTemplatePath()+"/maven-project-template/META-INF"), new File(PathUtil.getInstance(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfo()).getJavaResourcePath("config").getPath()+"META-INF"));
	}
	
	public static void makeController(ProjectInfo projectInfo) {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/merchant/login/LoginMerchantController.java", pathUtil.getControllerPackagePath().getPath()+"merchant/login/LoginMerchantController.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/boss/login/LoginController.java", pathUtil.getControllerPackagePath().getPath()+"boss/login/LoginController.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/boss/login/BossIndexController.java", pathUtil.getControllerPackagePath().getPath()+"boss/login/BossIndexController.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/boss/login/dto/BossLoginForm.java", pathUtil.getControllerPackagePath().getPath()+"boss/login/dto/BossLoginForm.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/boss/login/dto/LoginResult.java", pathUtil.getControllerPackagePath().getPath()+"boss/login/dto/LoginResult.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/menu/MenuController.java", pathUtil.getControllerPackagePath().getPath()+"system/menu/MenuController.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/bossuser/BossUserController.java", pathUtil.getControllerPackagePath().getPath()+"system/bossuser/BossUserController.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/bossuser/PasswdController.java", pathUtil.getControllerPackagePath().getPath()+"system/bossuser/PasswdController.java", projectInfo);
		/* sysparam模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/sysparam/SysParamController.java", pathUtil.getControllerPackagePath().getPath()+"system/sysparam/SysParamController.java", projectInfo);
		/* resource模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/resource/SysResourceController.java", pathUtil.getControllerPackagePath().getPath()+"system/resource/SysResourceController.java", projectInfo);
		/* 角色和角色权限分配模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/controller/system/sysrole/SysRoleController.java", pathUtil.getControllerPackagePath().getPath()+"system/sysrole/SysRoleController.java", projectInfo);
	}
	
	public static void makeDal(ProjectInfo projectInfo) {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/roleresource/MySysRoleResourceMapper.java", pathUtil.getDalPackagePath().getPath()+"mybatis/mymapper/MySysRoleResourceMapper.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/roleresource/RoleResource.java", pathUtil.getDalPackagePath().getPath()+"mybatis/mymodel/RoleResource.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/roleresource/MySysRoleResourceMapper.xml", pathUtil.getJavaResourcePath("dal").getPath()+"mybatis/myxml/MySysRoleResourceMapper.xml", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/userole/MyBossUserMapper.java", pathUtil.getDalPackagePath().getPath()+"mybatis/mymapper/MyBossUserMapper.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/userole/BossUserRole.java", pathUtil.getDalPackagePath().getPath()+"mybatis/mymodel/BossUserRole.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/mapper/userole/MyBossUserMapper.xml", pathUtil.getJavaResourcePath("dal").getPath()+"mybatis/myxml/MyBossUserMapper.xml", projectInfo);
		
	}
	
	public static void makeSecurity(ProjectInfo projectInfo) {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/pam/MallModularRealmAuthenticator.java", pathUtil.getServicePackagePath().getPath()+"security/pam/MallModularRealmAuthenticator.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/credential/RetryLimitHashedCredentialsMatcher.java", pathUtil.getServicePackagePath().getPath()+"security/credential/RetryLimitHashedCredentialsMatcher.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/authc/MallUsernamePasswordToken.java", pathUtil.getServicePackagePath().getPath()+"security/authc/MallUsernamePasswordToken.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/filter/KickoutSessionFilter.java", pathUtil.getServicePackagePath().getPath()+"security/filter/KickoutSessionFilter.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/filter/MyLogoutFilter.java", pathUtil.getServicePackagePath().getPath()+"security/filter/MyLogoutFilter.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/filter/MallFormAuthenticationFilter.java", pathUtil.getServicePackagePath().getPath()+"security/filter/MallFormAuthenticationFilter.java", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/realm/BossUserRealmImpl.java", pathUtil.getServicePackagePath().getPath()+"security/realm/BossUserRealmImpl.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/realm/MerchantUserRealmImpl.java", pathUtil.getServicePackagePath().getPath()+"security/realm/MerchantUserRealmImpl.java", projectInfo);

		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/dto/BossRolePojo.java", pathUtil.getServicePackagePath().getPath()+"security/dto/BossRolePojo.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/dto/LoginUserInfo.java", pathUtil.getServicePackagePath().getPath()+"security/dto/LoginUserInfo.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/dto/ShiroConfigDto.java", pathUtil.getServicePackagePath().getPath()+"security/dto/ShiroConfigDto.java", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/ShiroConfiguration.java", pathUtil.getServicePackagePath().getPath()+"security/ShiroConfiguration.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/security/SessionService.java", pathUtil.getServicePackagePath().getPath()+"security/SessionService.java", projectInfo);
	}
	
	public static void makeService(ProjectInfo projectInfo) {
		/* sysparam service */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysparam/dto/SysParamAddItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/sysparam/dto/SysParamAddItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysparam/dto/SysParamQueryFilter.java", pathUtil.getServicePackagePath().getPath()+"system/sysparam/dto/SysParamQueryFilter.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysparam/dto/SysParamUpdateItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/sysparam/dto/SysParamUpdateItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysparam/SysParamService.java", pathUtil.getServicePackagePath().getPath()+"system/sysparam/SysParamService.java", projectInfo);
		/* make user service */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/user/BossUserService.java", pathUtil.getServicePackagePath().getPath()+"system/user/BossUserService.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/user/dto/BossUserAddItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/user/dto/BossUserAddItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/user/dto/BossUserChangePasswdReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/user/dto/BossUserChangePasswdReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/user/dto/BossUserQueryFilter.java", pathUtil.getServicePackagePath().getPath()+"system/user/dto/BossUserQueryFilter.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/user/dto/BossUserUpdateItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/user/dto/BossUserUpdateItemReqDto.java", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/menu/dto/MenuNode.java", pathUtil.getServicePackagePath().getPath()+"system/menu/dto/MenuNode.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/menu/dto/TreeGridDto.java", pathUtil.getServicePackagePath().getPath()+"system/menu/dto/TreeGridDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/menu/dto/MenuNodeRsp.java", pathUtil.getServicePackagePath().getPath()+"system/menu/dto/MenuNodeRsp.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/menu/MenuService.java", pathUtil.getServicePackagePath().getPath()+"system/menu/MenuService.java", projectInfo);

		/* 资源管理模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/resource/dto/SysResourceAddItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/resource/dto/SysResourceAddItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/resource/dto/SysResourceAddItemRspDto.java", pathUtil.getServicePackagePath().getPath()+"system/resource/dto/SysResourceAddItemRspDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/resource/dto/SysResourceTree.java", pathUtil.getServicePackagePath().getPath()+"system/resource/dto/SysResourceTree.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/resource/dto/SysResourceUpdateItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/resource/dto/SysResourceUpdateItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/resource/SysResourceService.java", pathUtil.getServicePackagePath().getPath()+"system/resource/SysResourceService.java", projectInfo);
		
		/* 角色和角色权限分配模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysrole/dto/SysRoleAddItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/sysrole/dto/SysRoleAddItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysrole/dto/SysRoleUpdateItemReqDto.java", pathUtil.getServicePackagePath().getPath()+"system/sysrole/dto/SysRoleUpdateItemReqDto.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysrole/dto/SysRoleQueryFilter.java", pathUtil.getServicePackagePath().getPath()+"system/sysrole/dto/SysRoleQueryFilter.java", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/sysrole/SysRoleService.java", pathUtil.getServicePackagePath().getPath()+"system/sysrole/SysRoleService.java", projectInfo);
	}
	
	public static void afterBuild(ProjectInfo projectInfo) {
		FileUtil.batchDeleteModel(PathUtil.getInstance(projectInfo), "SysOpenssl", 
				"BossOptLog",
				"SysShortCut",
				"SysShortCutExample",
				"Example",
				"BossOptLogDefine",
				"BossOptLogDefineExample",
				"BossOptLogExample",
				"BossOptLogIgnore",
				"BossOptLogIgnoreExample",
				"SysFiles",
				"SysFilesExample",
				"SysOpensslExample");
		
		FileUtil.batchDeleteMapper(PathUtil.getInstance(projectInfo), "SysOpensslMapper",
				"BossOptLogDefineMapper",
				"BossOptLogMapper",
				"SysShortCutMapper",
				"ExampleMapper",
				"SysFilesMapper",
				"BossOptLogIgnoreMapper");
		
		FileUtil.batchDeleteMybatisXML(PathUtil.getInstance(projectInfo), "BossOptLogDefineMapper",
				"BossOptLogIgnoreMapper",
				"BossOptLogMapper",
				"SysShortCutMapper",
				"SysFilesMapper",
				"ExampleMapper",
				"SysOpensslMapper");
	}
	private Pattern pattern = Pattern.compile("'.*'");
	
	public void build(String cmd,String dir) throws Exception {
		Process p = Runtime.getRuntime().exec("cmd /c "+cmd, null, new File(dir));
		BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(),"gbk"), 1024);
		String tmp;
		while((tmp = br.readLine())!=null){
			System.out.println(tmp);
		}
		p.waitFor();
		p.destroy();
		killProcess();
	}
	
	public Map<String, List<String>> getEnums(List<ColumnInfo> columns) {
		Map<String, List<String>> enums = new HashMap<String, List<String>>();
		
		for(ColumnInfo columnInfo:columns) {
			if(columnInfo.getColumnType().indexOf("enum") >= 0) {
				Matcher m = pattern.matcher(columnInfo.getColumnType());
				if(m.find()) {
					List<String> list = new ArrayList<>();
					String[] tmp = m.group(0).replaceAll("'", "").split(",");
					boolean yesnoEnum = false;
					for(String s : tmp) {
						list.add(s);
						if(s.equals("YES")||s.equals("NO")) {
							yesnoEnum = true;
						}
					}
					if(tmp.length == 2 && yesnoEnum) {
						columnInfo.setYesnoEnum(yesnoEnum);
					} else {
						enums.put(columnInfo.getJavaCode(), list);
					}
				}
			}
		}
		
		return enums;
	}
	
	public void killProcess() {
        Runtime rt = Runtime.getRuntime();
        try {
            rt.exec("cmd.exe /C start wmic process where name='cmd.exe' call terminate");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
	public void makeEnums(ProjectInfo projectInfo) {
		
		List<TableInfo> tables = projectInfo.getTables();
		for(TableInfo table:tables) {
			List<ColumnInfo> columns = table.getColumns();
			Map<String, List<String>> allenums = getEnums(columns);
			StringBuilder sb = new StringBuilder();
			if(allenums.keySet().size() > 0) {
				allenums.forEach((key,list) -> {
					sb.append(key+",");
				});
				System.out.println(table.getTableName()+"找到枚举"+allenums.keySet().size()+"个,"+sb);
			}
			EnumInfo enumInfo = new EnumInfo();
			enumInfo.setTableName(NameUtil.getClassName(NameUtil._2JavaName(table.getTableName())));
			enumInfo.setArtifactId(projectInfo.getArtifactId());
			enumInfo.setCompanyName(projectInfo.getCompanyName());
			allenums.forEach((key,enums) ->{
				enumInfo.setEnumName(StringUtils.capitalize(key));
				enumInfo.setEnumValues(enums);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/service/EnumTemplate.java",
						pathUtil.getDalPackagePath().getPath()+"mybatis/enums/"+enumInfo.getTableName()+enumInfo.getEnumName()+"Enum.java"
						, enumInfo);
			});
		}
	}
	
	public void makeHtmlOfLayui(ProjectInfo projectInfo) throws Exception {
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/merchant/login-layui.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/merchant/login-layui.html", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/boss/login-layui.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/boss/login-layui.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/boss/index.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/boss/index.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/boss/console.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/boss/console.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/menu/menu.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/menu/menu.html", projectInfo);
		
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/include/layui-top.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/include/layui-top.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/include/layui-end.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/include/layui-end.html", projectInfo);
		FileUtils.copyDirectory(new File(projectInfo.getTemplatePath()+"/maven-project-template/view"), new File(pathUtil.getJavaResourcePath("assemble").getPath()+"public/"));

		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/bossUser/bossUser-change-passwd.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/bossUser/bossUser-change-passwd.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/bossUser/bossUser-list.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/bossUser/bossUser-list.html", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/resource/sysResource-list.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/resource/sysResource-list.html", projectInfo);
		/* 角色和角色权限分配模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/sysRole/sysRole-list.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/sysRole/sysRole-list.html", projectInfo);
		/* 系统参数模块 */
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/html/system/sysParam/sysParam-list.html", pathUtil.getJavaResourcePath("assemble").getPath()+"templates/system/sysParam/sysParam-list.html", projectInfo);
		
	}
	
	public void model(ProjectInfo projectInfo) throws Exception{
		String[] modelNames = new String[]{"assemble","common-util","dal","facade","biz",
				"web","integration","autotest","test","config"};
		for(String modelName:modelNames){
			projectInfo.setModelName(modelName);
			pathUtil.getJavaSourcePath(modelName).makedir();
			pathUtil.getJavaResourcePath(modelName).makedir();
			pathUtil.getTestJavaSourcePath("test").makedir();
			pathUtil.getTestJavaResourcePath("test").makedir();
			if(modelName.equalsIgnoreCase("dal")){
				
				new File(pathUtil.getDalPackagePath().getPath()+"mybatis/mapper").mkdirs();
				new File(pathUtil.getDalPackagePath().getPath()+"mybatis/mymapper").mkdirs();
				new File(pathUtil.getDalPackagePath().getPath()+"mybatis/model").mkdirs();
				new File(pathUtil.getDalPackagePath().getPath()+"mybatis/mymodel").mkdirs();
				
				new File(pathUtil.getJavaResourcePath("dal").getPath()+"mybatis/xml").mkdirs();
				new File(pathUtil.getJavaResourcePath("dal").getPath()+"mybatis/myxml").mkdirs();
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/generatorConfig.properties", pathUtil.getJavaResourcePath("dal").getPath()+"mybatis-generator/generatorConfig.properties", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/generatorConfig.xml", pathUtil.getJavaResourcePath("dal").getPath()+"mybatis-generator/generatorConfig.xml", projectInfo);
			}
			if(modelName.equalsIgnoreCase("assemble")){
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/App.java", pathUtil.getAssemblePackagePath().getPath()+"Application.java", projectInfo);
				File templatePath = new File(pathUtil.getJavaResourcePath(modelName).getPath(),"/templates");
				templatePath.mkdirs();
			}
			if(modelName.equalsIgnoreCase("config")){
//				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/RestTemplateConfig.java", pathUtil.getConfigPackagePath().getPath()+"net/RestTemplateConfig.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/doc/Knife4jConfig.java", pathUtil.getConfigPackagePath().getPath()+"doc/Knife4jConfig.java", projectInfo);
//				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/swagger/Swagger3Config.java", pathUtil.getConfigPackagePath().getPath()+"swagger/Swagger3Config.java", projectInfo);
//				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/swagger/SwaggerProvider.java", pathUtil.getConfigPackagePath().getPath()+"swagger/SwaggerProvider.java", projectInfo);
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/undertow/CustomizationBean.java", pathUtil.getConfigPackagePath().getPath()+"undertow/CustomizationBean.java", projectInfo);
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/filter/RequestLogFilter.java", pathUtil.getConfigPackagePath().getPath()+"filter/RequestLogFilter.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/filter/MyRequestWrapper.java", pathUtil.getConfigPackagePath().getPath()+"filter/MyRequestWrapper.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/filter/RequestReadUtils.java", pathUtil.getConfigPackagePath().getPath()+"filter/RequestReadUtils.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/config/ThreadPoolTaskConfig.java", pathUtil.getConfigPackagePath().getPath()+"system/ThreadPoolTaskConfig.java", projectInfo);
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/AnsiLevel.java", pathUtil.getConfigPackagePath().getPath()+"logback/AnsiLevel.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/ColorByLevel.java", pathUtil.getConfigPackagePath().getPath()+"logback/ColorByLevel.java", projectInfo);
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/log.properties", pathUtil.getJavaResourcePath("config").getPath()+"logback/log.properties", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/logback.xml", pathUtil.getJavaResourcePath("config").getPath()+"logback/logback.xml", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/application-dev.yml", pathUtil.getJavaResourcePath("config").getPath()+"application-dev.yml", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/application.yml", pathUtil.getJavaResourcePath("config").getPath()+"application.yml", projectInfo);
				
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/ehcache/ehcache.xml", pathUtil.getJavaResourcePath("config").getPath()+"ehcache/ehcache.xml", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/ehcache/ehcache.xsd", pathUtil.getJavaResourcePath("config").getPath()+"ehcache/ehcache.xsd", projectInfo);
			}
			
			if(modelName.equalsIgnoreCase("test")){
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/test/TestBase.java", pathUtil.getTestPackagePath().getPath()+"TestBase.java", projectInfo);
				TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/test/MyTest.java", pathUtil.getTestPackagePath().getPath()+"example/MyTest.java", projectInfo);
				
			}
			TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/jar-pom.xml", pathUtil.getModelPath(modelName).getPath()+"/pom.xml", projectInfo);
		}
		/* make other things */
		makeEnums(projectInfo);
		makeHtmlOfLayui(projectInfo);
	}
	
	public ResultBase parent(ProjectInfo projectInfo) throws Exception{
		ResultBase result = new ResultBase();
		File parentPath = new File(projectInfo.getProjectPath()+"/"+projectInfo.getArtifactId());
		parentPath.mkdirs();
		String pom = parentPath+"/pom.xml";
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/parent-pom.xml", pom, projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/startup.sh", parentPath+"/startup.sh", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/offline-deploy.sh", parentPath+"/offline-deploy.sh", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/run.bat", parentPath+"/startup.bat", projectInfo);
		TemplateUtil.getInstance(projectInfo.getTemplatePath()).build("/maven-project-template/facade-deploy.bat", parentPath+"/facade-deploy.bat", projectInfo);
		model(projectInfo);
		return result;
	}
	
}
